// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    catelist: ["男装", "女装", "家具", "数码", "手机", "运动", "床上用品"],
    bannerlist: [{
      url: "../../images/banner1.jpg"
    }, {
      url: "../../images/banner2.jpg"
    }, {
      url: "../../images/banner3.jpg"
    }],
    danmulist: [{
        text: "网院",
        corlor: "#ff0000",
        time: 1
      },
      {
        text: "电大",
        corlor: "#e64e69",
        time: 30
      }
    ],
    latitude: "",
    longittude: ""
  },
  onLoad() {

  },
  saveUserInfo: function () {
    //同步缓存
    var data = {
      "name": "李志强",
      "student_id": "201965110451"
    }
    wx.setStorageSync('userinfo', data)
    //异步缓存
    wx.setStorage({
      key: "studentinfo",
      data: {
        "sex": "男",
        "age": 21
      }
    })
  },
  getUserInfo: function () {
    //同步获取缓存数据
    var studentinfo = wx.getStorageSync('studentinfo');
    console.log(studentinfo);
    //异步获取数据
    wx.getStorage({
      key: 'userinfo',
      success(res) {
        console.log(res);
      }
    })
    //获取小程序中所有的缓存信息
    wx.getStorageInfo({
      success: (option) => {
        console.log(option)
      },
    })
  },
  removeUserInfo: function () {
    //异步移除
    wx.removeStorage({
      key: 'userinfo',
    })
    wx.removeStorageSync('studentinfo')
  },
  getLocal: function () {
    var then = this;
    wx.getLocation({
      type: "gcj02",
      success(res) {
        then.setData({
          latitude: res.latitude,
          longittude: res.longitude,

        })
      }
    })
  },
  openMap: function () {
    var then = this;
    wx.openLocation({
      latitude: then.data.latitude,
      longitude: then.data.longittude,
      name: "湖南开放大学终教楼1104",
      address: "湖南省长沙市天心区青园路168号1104"
    })
  },
  selectLocal: function () {
    var then = this;
    wx.chooseLocation({
      latitude: then.data.latitude,
      longitude: then.data.longittude
    })
  },
  call:function(){
      wx.makePhoneCall({
        phoneNumber: '17670654107',
      })
  },
  scanCode:function(){
      wx.scanCode({
        onlyFromCamera: true,
        success(res){
          console.log(res);
        }
      })
  },
  checkboxChange: function (e) {
    var then = this;
    var likestr = "";
    for (let index = 0; index < e.detail.value.length; index++) {
      likestr = likestr + e.detail.value[index];
    }

    then.setData({
      likes: likestr
    })
    console.log(e)
    console.log(e.detail.value[0])
  },
})